package cn.fuxue.hrms.web.admin_controller;

import cn.fuxue.hrms.common.entity.Role;
import cn.fuxue.hrms.service.PermissionsRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/admin/role")
public class PermissionRoleController {
    @Autowired
    private PermissionsRoleService permissionsRoleService;

    @GetMapping("/selectAll")
    public String selectAll(Model model) {
        List<Role> roleList = permissionsRoleService.selectAllRole();
        model.addAttribute("roleList", roleList);
        return "admin/permissions_role";
    }

    /**
     * 添加角色信息
     * @param role 角色实体对象
     * @return 添加结果
     */
    @PostMapping("/addRole")
    public String addRole(@RequestBody Role role) {
         permissionsRoleService.insertRole(role);
         return "redirect:/admin/role/selectAll";
    }


    /**
     * 根据角色 ID 删除角色信息
     * @param Id 角色 ID
     * @return permissions_role页面
     */
    @GetMapping("/delete/{Id}")
    public String deleteRoleById(@PathVariable Integer Id) {
        /*return permissionsRoleService.deleteRoleById(Id);*/
         permissionsRoleService.deleteRoleById(Id);
         return "redirect:/admin/role/selectAll";
    }


}
